Skip to content

Commit

Permalink
showing how to use einsum to reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
unrealwill committed May 1, 2024
1 parent f29802d commit 9a8c753
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fftKAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def forward(self,x):
if( self.addbias):
y += self.bias
#End fuse
'''
#You can use einsum instead to reduce memory usage
#It stills not as good as fully fused but it should help
#einsum is usually slower though
c = th.reshape(c,(1,x.shape[0],x.shape[1],self.gridsize))
s = th.reshape(s,(1,x.shape[0],x.shape[1],self.gridsize))
y2 = th.einsum( "dbik,djik->bj", th.concat([c,s],axis=0) ,self.fouriercoeffs )
if( self.addbias):
y2 += self.bias
diff = th.sum((y2-y)**2)
print("diff")
print(diff) #should be ~0
'''
y = th.reshape( y, outshape)
return y

Expand Down

0 comments on commit 9a8c753

Please sign in to comment.